﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Data;
using System.Data.SqlClient;

namespace AutoCreateFolder
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Usage:AutoCreateFolder \"ConnectionString\"");
                Console.WriteLine("ConnectionString is must");
                Console.WriteLine("Integrate:Data Source={ServerName};Initial Catalog={DataBaseName};Integrated Security=True");
                Console.WriteLine("User Login:Data Source={ServerName};Initial Catalog={DataBaseName};User ID={UserName};Password={Password}");
                return;
            }
            //Data Source=IFCA-LIUJU;Initial Catalog=SPSetia_Live;Integrated Security=True
            //Data Source=IFCA-LIUJU;Initial Catalog=SPSetia_Live;User ID=sa;Password=loubliuju
            string ConnStr = args[0];
            string sqlStr = @"
select CF_Account.AccountNo from CF_Company
inner join CF_Account on CF_Account.AccountID=CF_Company.AccountID
where CF_Company.RecordStatus='Active' and CF_Account.AccountID<>1
";
            DataSet ds = new DataSet();
            try
            {
                using (SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, ConnStr))
                {
                    adapter.Fill(ds);
                }
                Common comm = new Common();
                List<DirectoryInfo> CompanyDI = comm.CreateCompanyFolder(ds);
                List<DirectoryInfo> YearDI = comm.CreateYearFolder(CompanyDI);
                List<DirectoryInfo> MonthDI = comm.CreateMonthFolder(YearDI);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}
